package com.core.baseManager;

import java.io.Serializable;
import java.util.Map;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.core.baseDao.extend.Pager;
import com.core.baseDao.extend.impl.BaseEntityDaoImpl;

/**
 * Manager基类，调用GenericDAO实现实体的CRUD操作
 * @author
 * @param <T> 实体类型
 * @param <PK> 实体主键类型
 */
public class GenericManager<T, PK extends Serializable> extends BaseEntityDaoImpl<T, PK> {
    /**
     * Log variable for all child classes. Uses LogFactory.getLog(getClass()) from Commons Logging
     */
    protected final Log log = LogFactory.getLog(getClass());

    public Pager findByPage(String hql, Map<String, Object> params, Pager pager){
		StringBuffer sb = new StringBuffer(hql);
		if (params != null && params.size() > 0) {
			sb.append("t where 1=1 ");
			Set<String> key = params.keySet();
			for (String tempkey : key) {
				sb.append(" and t.");
				sb.append(tempkey);
				sb.append("='");
				sb.append(params.get(tempkey));
				sb.append("'");
				log.info(sb.toString());
			}
		}
    	return this.getByPage(sb.toString(), pager);
    }
    
}
